-- @owner: cr13
-- @date: 2025/3/27
-- @testpoint:重建的函数参数数量不同且最后一个参数有默认值，部分合理报错
--step1: 创建函数;expect:成功
drop function if exists add_numbers(p_num1 int,p_num2 int);
CREATE FUNCTION add_numbers(
p_num1 INT,
p_num2 INT default 1
) RETURNS INT
AS $$
BEGIN
RETURN p_num1 + p_num2;
END;
$$ LANGUAGE plpgsql;
/
--step2: 创建视图;expect:成功
drop view if exists v_ddl0043;
create view v_ddl0043 as select add_numbers(1,2);
--step3: 查询视图;expect:成功
select * from v_ddl0043;
--step4: 删除函数;expect:成功
drop function if exists add_numbers(p_num1 int,p_num2 int);
--step5: 重建函数，参数数量不同且最后一个参数有默认值;expect:成功
CREATE FUNCTION add_numbers(
p_num1 INT,
p_num2 INT,
p_num3 INT DEFAULT 1
) RETURNS INT
AS $$
BEGIN
RETURN p_num1 + p_num2 + p_num3;
END;
$$ LANGUAGE plpgsql;
/
--step6: 查询视图;expect:成功
select * from v_ddl0043;
--step7: 查询视图状态;expect:有效
select valid from pg_object where object_oid='v_ddl0043'::regclass;
--step8: 查询视图定义;expect:成功
select pg_get_viewdef('v_ddl0043');
--step9: 清理环境;expect:成功
drop view if exists v_ddl0043;
drop function if exists add_numbers(p_num1 int,p_num2 int,p_num3 int);
